package com.pinyougou.manager.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.PageResult;
import com.pinyougou.pojo.Result;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("brand")
public class BrandController {

    @Reference
    private BrandService brandService;

    //查询所有品牌列表
    @RequestMapping("list")
    public List<TbBrand> findAll(){
        return brandService.findAll();
    }

    //带条件分页查询品牌列表
    @RequestMapping("search")
    public PageResult pageAll(int page,int pageSize,@RequestBody(required = false) TbBrand tbBrand){
        return brandService.findPage(tbBrand,page,pageSize);
    }

    @RequestMapping("add")
    public Result addBrand(@RequestBody TbBrand tbBrand){
        try {
            brandService.add(tbBrand);
            return new Result(true,"添加成功！！");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"添加失败！");
        }
    }

    @RequestMapping("update")
    public Result updateBrand(@RequestBody TbBrand tbBrand){
        try {
            brandService.update(tbBrand);

            return new Result(true,"修改成功！！");

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"修改失败！");
        }
    }

    @RequestMapping("delete")
    public Result deleteChoose(Long[] ids){
        try {
            brandService.delete(ids);
            return new Result(true,"删除成功！！");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除失败！");
        }
    }

    @RequestMapping("findBrandList")
    public List<Map> findBrandList(){
        return brandService.findBrandList();
    }
}
